﻿
Module ControlsModule
#Region "Clients Player Controls"
    '' Standalone player controls
    Public Sub StandalonePlayerControl(ByRef action As String, type As String)
        Select Case action

            '' Back Button actions to take depending on the variable for
            Case "back"
                FormMain.wmp.Ctlcontrols.previous()

                '' stop Button actions to take depending on the variable for
            Case "stop"
                FormMain.wmp.Ctlcontrols.stop()
                FormMain.pct01Back.Enabled = False
                FormMain.pct02Stop.Enabled = False
                FormMain.pct03Pause.Enabled = False
                FormMain.pct04Play.Enabled = True
                FormMain.pct05Next.Enabled = False

                '' pause Button actions to take depending on the variable for
            Case "pause"
                FormMain.wmp.Ctlcontrols.pause()
                FormMain.pct01Back.Enabled = False
                FormMain.pct02Stop.Enabled = True
                FormMain.pct03Pause.Enabled = False
                FormMain.pct04Play.Enabled = True
                FormMain.pct05Next.Enabled = False

                '' play Button actions to take depending on the variable for
            Case "play"
                FormMain.wmp.Ctlcontrols.play()
                FormMain.pct01Back.Enabled = True
                FormMain.pct02Stop.Enabled = True
                FormMain.pct03Pause.Enabled = True
                FormMain.pct04Play.Enabled = True
                FormMain.pct05Next.Enabled = True

                '' next Button actions to take depending on the variable for
            Case "next"
                FormMain.wmp.Ctlcontrols.next()

                '' file Button actions to take depending on the variable for
            Case "file"
                StandaloneOpenPlaylist()

                '' volume Button actions to take depending on the variable for
            Case "volume"


                '' power Button actions to take depending on the variable 
            Case "power"

        End Select
    End Sub

    '' Winamp player controls
    Public Sub WinampPlayerControl(ByRef action As String, type As String)
        Select Case action

            '' Back Button actions to take depending on the variable for
            Case "back"
                WinampControl.WinampControl.WAPrevTrack()

                '' stop Button actions to take depending on the variable for
            Case "stop"
                WinampControl.WinampControl.WaStop()

                '' pause Button actions to take depending on the variable for
            Case "pause"
                WinampControl.WinampControl.WAPause()

                '' play Button actions to take depending on the variable for
            Case "play"
                WinampControl.WinampControl.WAPlay()

                '' next Button actions to take depending on the variable for
            Case "next"
                WinampControl.WinampControl.WANextTrack()

                '' file Button actions to take depending on the variable for
            Case "file"
                WinampControl.WinampControl.WAFile()

                '' volume Button actions to take depending on the variable for
            Case "volume"


                '' power Button actions to take depending on the variable 
            Case "power"

        End Select
    End Sub

    '' iTunes player controls
    Public Sub iTunesPlayerControl(ByRef action As String, type As String)
        Select Case action

            '' Back Button actions to take depending on the variable for
            Case "back"


                '' stop Button actions to take depending on the variable for
            Case "stop"


                '' pause Button actions to take depending on the variable for
            Case "pause"


                '' play Button actions to take depending on the variable for
            Case "play"


                '' next Button actions to take depending on the variable for
            Case "next"


                '' file Button actions to take depending on the variable for
            Case "file"


                '' volume Button actions to take depending on the variable for
            Case "volume"


                '' power Button actions to take depending on the variable 
            Case "power"

        End Select
    End Sub
#End Region

#Region "Open Files for playlist"

    Public Sub StandaloneOpenPlaylist()
        Dim playlist As WMPLib.IWMPPlaylist
        Dim newmedia As WMPLib.IWMPMedia

        playlist = FormMain.wmp.newPlaylist("NowPlaying", "") 'resets the playlist for everytime you open files
        FormMain.wmp.currentPlaylist = playlist
        If FormMain.OpenPlaylist.ShowDialog = DialogResult.OK Then 'opens dialog box to allow user to select m3u or wpl
            newmedia = FormMain.wmp.newMedia(FormMain.OpenPlaylist.FileName) 'sets the newmedia
            FormMain.wmp.currentPlaylist.insertItem(0, newmedia) 'inserts the new media into playlist
            FormMain.pct04Play.Enabled = True
            sPlayerReady = True
            FormMain.pct04Play.Enabled = True
        Else
            sPlayerReady = False
        End If
    End Sub

#End Region

#Region "Display Information in Windower"
    Public Sub StandaloneDisplayString(ByVal playstate As String)
        If WinInit.Detect = True Then
            If sPlayerReady = True Then
                If My.Settings.WindowerDisplay = 0 Then
                    WindowerDisplayString = ""
                    WindowerDisplayString = "FFXI Media Player"
                    If STrack.PlayStateInt <> 3 Then WindowerDisplayString = WindowerDisplayString + " " + playstate
                    If My.Settings.ShowArtist = True Then WindowerDisplayString = WindowerDisplayString + " :- " + "Artist: " + STrack.Artist + " "
                    If My.Settings.ShowTitle = True Then WindowerDisplayString = WindowerDisplayString + "| Title: " + STrack.Title + " "
                    If My.Settings.ShowDuration = True Then WindowerDisplayString = WindowerDisplayString + "| Duration: " + STrack.Possition + "/" + STrack.Duration
                ElseIf My.Settings.WindowerDisplay = 1 Then
                    WindowerDisplayString = ""
                    WindowerDisplayString = "FFXI Media Player"
                    If STrack.PlayStateInt <> 3 Then WindowerDisplayString = WindowerDisplayString + vbNewLine + STrack.PlayStateSTR
                    If My.Settings.ShowArtist = True Then WindowerDisplayString = WindowerDisplayString + vbNewLine + "Artist: " + STrack.Artist
                    If My.Settings.ShowTitle = True Then WindowerDisplayString = WindowerDisplayString + vbNewLine + "Title: " + STrack.Title
                    If My.Settings.ShowDuration = True Then WindowerDisplayString = WindowerDisplayString + vbNewLine + "Duration: " + STrack.Possition + "/" + STrack.Duration
                End If
            End If
        End If
    End Sub
    Public Function StandalonePlaystate(ByRef state As Integer)
        If state < 13 Then
            Select Case state
                Case 0 '' Playstate = Undefined
                    If My.Settings.WindowerDisplay = 0 Then Return "[Idle]" Else Return "Player Idle"

                Case 1 '' Playstate = Stopped
                    If My.Settings.WindowerDisplay = 0 Then Return "[Stopped]" Else Return "Player Stopped"

                Case 2 '' PlayState = Paused
                    If My.Settings.WindowerDisplay = 0 Then Return "[Paused]" Else Return "Player Paused"

                Case 3 '' Playstate = Playing
                    If My.Settings.WindowerDisplay = 0 Then Return "[Playing]" Else Return "Player Playing"

                Case 4 '' Playstate = Scanning Forward
                    If My.Settings.WindowerDisplay = 0 Then Return "[Scanning]" Else Return "Player Scanning"

                Case 5 '' Playstate = Scanning Back
                    If My.Settings.WindowerDisplay = 0 Then Return "[Scanning]" Else Return "Player Scanning"

                Case 6 '' Playstate = Buffering
                    If My.Settings.WindowerDisplay = 0 Then Return "[Buffering]" Else Return "Player Buffering"

                Case 7 '' Playstate = Waiting
                    If My.Settings.WindowerDisplay = 0 Then Return "[Waiting]" Else Return "Player Waiting"

                Case 8 '' Playstate = Media Ended
                    If My.Settings.WindowerDisplay = 0 Then Return "[Media Ended]" Else Return "Media Ended"

                Case 9 '' Playstate = Transitioning
                    If My.Settings.WindowerDisplay = 0 Then Return "[Transitioning]" Else Return "Player Transitioning"

                Case 10 '' Playstate = Ready
                    If My.Settings.WindowerDisplay = 0 Then Return "[Ready]" Else Return "Player Ready"

                Case 11 '' Playstate = Reconnecting
                    If My.Settings.WindowerDisplay = 0 Then Return "[Reconnecting]" Else Return "Reconnecting"

                Case 12 '' Playstate = Last
                    If My.Settings.WindowerDisplay = 0 Then Return "[Last Media Item]" Else Return "Last Media Item"
            End Select
        Else
            Return "Play State Error"
        End If
    End Function

    Public Sub WinampDisplayString(ByVal playstate As String)
        If WinInit.Detect = True Then
            If My.Settings.WindowerDisplay = 0 Then
                WindowerDisplayString = ""
                WindowerDisplayString = "FFXIMP Winamp"
                If WTrack.PlayStateInt <> 1 Then WindowerDisplayString = WindowerDisplayString + " " + playstate
                If My.Settings.WinampSplit = 0 Or wSplit = False Then
                    If My.Settings.ShowArtist = True Then WindowerDisplayString = WindowerDisplayString + " : " + WTrack.Title
                    If My.Settings.ShowDuration = True Then WindowerDisplayString = WindowerDisplayString + " | Duration: " + WTrack.Possition + "/" + WTrack.Duration
                Else
                    If My.Settings.ShowArtist = True Then WindowerDisplayString = WindowerDisplayString + " : " + "Artist: " + WTrack.Artist.Trim + " "
                    If My.Settings.ShowTitle = True Then WindowerDisplayString = WindowerDisplayString + "| Title: " + WTrack.Title.Trim + " "
                    If My.Settings.ShowDuration = True Then WindowerDisplayString = WindowerDisplayString + "| Duration: " + WTrack.Possition + "/" + WTrack.Duration
                End If

            ElseIf My.Settings.WindowerDisplay = 1 Then
                WindowerDisplayString = ""
                WindowerDisplayString = "FFXIMP Winamp" + vbNewLine
                If WTrack.PlayStateInt <> 1 Then WindowerDisplayString = WindowerDisplayString + playstate + vbNewLine
                If My.Settings.WinampSplit = 0 Or wSplit = False Then
                    If My.Settings.ShowArtist = True Then WindowerDisplayString = WindowerDisplayString + WTrack.wintext + vbNewLine + "Duration: " + WTrack.Possition + "/" + WTrack.Duration
                Else
                    If My.Settings.ShowArtist = True Then WindowerDisplayString = WindowerDisplayString + "Artist: " + WTrack.Artist + vbNewLine
                    If My.Settings.ShowTitle = True Then WindowerDisplayString = WindowerDisplayString + "Title: " + WTrack.Title
                    If My.Settings.ShowDuration = True Then WindowerDisplayString = WindowerDisplayString + vbNewLine + "Duration: " + WTrack.Possition + "/" + WTrack.Duration
                End If
            End If

        End If
    End Sub

    Public Function WinampPlaystate(ByRef state As Integer)
        If state < 13 Then
            Select Case state
                Case 0 '' Playstate = Undefined
                    If My.Settings.WindowerDisplay = 0 Then Return "[Stopped]" Else Return "Player Stopped"

                Case 1 '' Playstate = Playing
                    If My.Settings.WindowerDisplay = 0 Then Return "[Playing]" Else Return "Player Playing"

                Case 2 '' PlayState = Paused
                    If My.Settings.WindowerDisplay = 0 Then Return "[Unknown 02]" Else Return "Playerstate unknown 2"

                Case 3 '' Playstate = Paused
                    If My.Settings.WindowerDisplay = 0 Then Return "[Paused]" Else Return "Player Paused"
            End Select
        Else
            Return "Play State Error"
        End If
    End Function

    Public Sub iTunesDisplayString()

    End Sub

    Public Sub UpdateDisplay()
        If PClient = 0 Then
            StandaloneDisplayString(STrack.PlayStateSTR)
        ElseIf PClient = 1 Then
            WinampDisplayString(WTrack.PlayStateSTR)
        ElseIf PClient = 2 Then
            iTunesDisplayString()
        End If
        DisplayTrack(WindowerDisplayString)
    End Sub
#End Region
End Module
